package chapter1.utils;

import java.io.InputStream;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PropsUtil {
	private static final Logger LOGGER=LoggerFactory.getLogger(PropsUtil.class);
	
	
	public static Properties loadProps(String fileName){
		Properties prop=null;
		try (InputStream is=Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName)){
			if(is!=null){
				prop=new Properties();
				prop.load(is);
			}
		} catch (Exception e) {
			LOGGER.error("load prop file fails",e);
		}
	
		
		return prop;
	}
	
	//获取属性文件的值
	public static String getString(Properties prop,String key){
		return getString(prop,key,"");
	}
	
	public static String getString(Properties prop,String key,String defaultValue){
         String value=	defaultValue;
         if(prop.containsKey(key)){
        	 value=prop.getProperty(key);
         }
		return value;
	}

}
